﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
/// <summary>
///ECountry 的摘要说明
/// </summary>
public class ECountry
{
	public ECountry()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public static string GetECountryVersion()
    {
        return "技术支持：<a href='http://www.ecountry.net.cn' target='_blank' title='地球村网络科技工作室'><b>ECountry.Ltd.</b></a> &nbsp;&nbsp;QQ：<a href='tencent://message/?uin=3062363&Site=地球村网络科技工作室&Menu=yes' title='QQ在线支持'>3062363<FONT color=#ffffff></FONT></a>";//&nbsp;&nbsp;Email：Admin@ECountry.net.cn
    }



    /// <summary>
    /// 检测远程URL注册日期是否有效
    /// </summary>
    public static bool IsValidCheck()
    {
        
        //string enddate="2008/12/28";
        //string IsValidDate = ReadTextFileDataFromURL("http://www.it110.net.cn/valid/IsValidCheck.txt");        
        string IsValidDate = ReadTextFileDataFromURL("http://"+ HttpContext.Current.Request.Url.Host.Trim() +"/valid/IsValidCheck.txt");

        if (IsValidDate == "无效日期格式" || !Public.Date_Check(IsValidDate))
        {
            IsValidDate = "20100515";
        }

        DateTime dtend = DateTime.ParseExact(IsValidDate, "yyyyMMdd", null);
        TimeSpan tsday = dtend - System.DateTime.Now;
        int daycount = (int)tsday.TotalDays;

        if (daycount <= 0)
        {
            //Console.Write("系统故障，请与开发者联系！");
            return false;
        }
        else 
        {
            return true;
        }
    }


    /// <summary>
    /// 按只读方式从远程URL中读取txt文件内容
    /// </summary>
    public static string  ReadTextFileDataFromURL(string strUrl)
    {
        try
        {
        string strContent;
        WebClient myclien = new WebClient();

        System.IO.StreamReader mystream = new System.IO.StreamReader(myclien.OpenRead(strUrl), System.Text.Encoding.GetEncoding("gb2312"));
        strContent = mystream.ReadToEnd().ToString().Trim();

        return strContent;
        }
        catch (System.Exception Ex)
        {
            return "无效日期格式";   //Ex.Message.ToString();
        }

    }



    /// <summary>
    /// 按只读方式来读取txt文件
    /// </summary>
    public static  string  ReadTextFileDate()
    {
        string strInput = "";
        string GetStream = "";

        string FileName = "http://192.168.1.8/IsValidCheck.txt";

        if (File.Exists(FileName))
        {
            Stream fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            TextReader sr = new StreamReader(fs, UnicodeEncoding.GetEncoding("gb2312"));
            strInput = sr.ReadLine();
            while (strInput != null)
            {
                GetStream += strInput;
                strInput = sr.ReadLine();
            }
            sr.Close();
            fs.Close();
        }
        else
        {
            GetStream = "你好。";
        }
        return GetStream;
        //ViewState["GetStream"] = GetStream.ToString();
    }

    //public static string StreamGetContent()
    //{
    //    ///<summary>   
    //    ///流方式读取网页内容，返回网页内容的全部字符,传入要抓取的网页地址   
    //    ///</summary>   

    //    //strUrl = FormatString(strUrl);
    //    string strUrl;
    //    strUrl = "http://www.hbhsqz.cn/IsValidCheck.txt";
    //    //if (CheckURL(strUrl))
    //        //if (strUrl)
    //        //{
    //        //try
    //        //{
    //            string strContent;
    //            WebClient myclien = new WebClient();

    //            System.IO.StreamReader mystream = new System.IO.StreamReader(myclien.OpenRead(strUrl), System.Text.Encoding.GetEncoding("gb2312"));
    //            strContent = mystream.ReadToEnd().ToString().Trim();

    //            return strContent;
    //        //}
    //        //catch (System.Exception Ex)
    //        //{
    //        //    return Ex.Message.ToString();
    //    //    //}
    //    //}
    //    //else
    //    //{
    //    //    return "您输入的地址不正确";
    //    //}
    //} 


  //  private   bool   CheckURL(string   strUrl)   
  //{   
  /////<summary>   
  /////检测输入的地址格式   
  /////</summary>   
    
  //if   (Regex.IsMatch(strUrl,@"(\s|\n|^)(\w+://[^\s\n]+)"))   
  //{   
  //return   true;   
  //}   
  //else   
  //{   
  //return   false;   
  //}   
  //}   


  //private   string   FormatString(string   strUrl)   
  //{   
  /////<summary>   
  /////检测输入的地址格式有没有包含URL前缀   
  /////</summary>   
    
  //if   (strUrl.ToLower().Substring(0,7)   !=   "http://")   
  //{   
  //strUrl   =   "http://"   +   strUrl;   
  //}   
  //return   strUrl;   
  //}   
  //}   


}
